# How Gendered is the Peer Review Process? A Mixed-Design Analysis of Reviewer Feedback
# Replication material
# =======================================================================================

### IMPORTANT:
# This script needs to be run from the main folder (i.e., the directory this script resides in)
# Assumes 00_script/, 01_data/, 02_output/01_tables/ and 02_output/02_figures/ are all in the same parent directory

# load libraries
library(here)
library(tidyverse)
library(lubridate)
library(xtable)
library(texreg)
library(DescTools)

library(tidytext)
library(ngram)
library(lfe)
library(quanteda)
#devtools::install_github("kbenoit/quanteda.dictionaries") 
library(quanteda.dictionaries)
library(diagis)


# make sure select() is dplyr::select() 
select <- dplyr::select

# load data
# =======================================================================================
manuscript_data <- read_csv(here("01_data", "manuscript_data.csv"))
reviewer_data <- read_csv(here("01_data", "reviewer_data.csv"))
reviewer_invitations <- read_csv(here("01_data", "reviewer_invitations_data.csv"))


# Make authorship data into factor variables
manuscript_data <- manuscript_data %>% mutate(
    gender_type = factor(gender_type, levels = c("Solo Male", "Solo Female","Male Team", "Female Team", "Mixed Team"))
    , gender_type3 = factor(gender_type3, levels = c("Mixed Team", "Male", "Female")))
    
reviewer_data <- reviewer_data %>% mutate(
  gender_type = factor(gender_type, levels = c("Solo Male", "Solo Female","Male Team", "Female Team", "Mixed Team"))
  , gender_type3 = factor(gender_type3, levels = c("Mixed Team", "Male", "Female")))

# Calculate review scores
# =======================================================================================
source(here("00_script", "review_scores.R"))

# =======================================================================================
### Main results
# =======================================================================================

# make Table 1
# =======================================================================================
source(here("00_script", "table_1.R"))

# make Figure 1
# =======================================================================================
source(here("00_script", "figure1.R"))

# make Table 2-3 and Figure 2
# =======================================================================================
source(here("00_script", "table2_3.R"))

# =======================================================================================
### Supplemental Information
# =======================================================================================


# make Figure S-1
# =======================================================================================
source(here("00_script", "SI_figure1.R"))

# make Table S-2
# =======================================================================================
source(here("00_script", "SI_table2.R"))

# make Table S-3
# =======================================================================================
source(here("00_script", "SI_table3.R"))

# make Table S-4
# =======================================================================================
source(here("00_script", "SI_table4.R"))
